/**
 *  贪心算法-跳跃游戏-力扣55
 */

public class Practice_5 {
    public static void main(String[] args) {
        int[] nums = {0, 3, 1, 1, 4};
        boolean result = canJump(nums);
        System.out.println(result);
    }
    public static boolean canJump(int[] nums) {

        if (nums == null || nums.length == 0) {
            return false;
        }
        if (nums != null && nums.length == 1) {
            return true;
        }

        int cover = 0;
        for (int i = 0; i <= cover; i++) {//注意i是小于等于cover，不是小于等于nums.length-1
            cover = Math.max(cover, i + nums[i]);
            if (cover >= nums.length - 1) {
                return true;
            }
        }
        return false;
    }
}
